using System.Collections;
using System.Collections.Generic;
using MyFrame.Pool;
using UnityEngine;

namespace Platform.Skill.Indicator
{
    public class DottedIndicator : BaseSkillIndicator
    {


        [Header("点抛物线")]
        [SerializeField] private int numberOfDots = 20;
        [SerializeField] private float spaceBetweenDots = 0.07f;
        // [SerializeField] private GameObject dotPrefab;
        // [SerializeField] private Transform dotsParent;
        private GameObject[] dots;

        void Awake()
        {
            GeneraeteDots();
        }

        void Update()
        {
            // if (PlayerInput.Instance.HasUseSkillInput)
            // {
            for (int i = 0; i < numberOfDots; i++)
            {
                dots[i].transform.position = DotsPosition(i * spaceBetweenDots);
            }
            // }
        }

        public override void Show()
        {
            base.Show();
            SetActive(true);
        }
        public override void Hide()
        {
            base.Hide();
            SetActive(false);
        }

        public void SetActive(bool isActive)
        {
            for (int i = 0; i < numberOfDots; i++)
            {
                dots[i].SetActive(isActive);
            }
        }

        private void GeneraeteDots()
        {
            dots = new GameObject[numberOfDots];
            for (int i = 0; i < numberOfDots; i++)
            {
                dots[i] = PoolMgr.Instance.GetObj("Dot", transform.position, Quaternion.identity);
                // dots[i] = Instantiate(dotPrefab, entity.transform.position, Quaternion.identity, dotsParent);
                dots[i].SetActive(false);
            }
        }
        /// <summary>
        /// 计算抛物线
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        private Vector2 DotsPosition(float t)
        {
            var pos = (Vector2)Tool.GetEntityCenterByCollider(entity.transform) +
            new Vector2(Tool.GetMouseDirection().normalized.x * skillData.launchForce.x,
                Tool.GetMouseDirection().normalized.y * skillData.launchForce.y) * t
                + 0.5f * (Physics2D.gravity * skillData.gravity) * Mathf.Pow(t, 2);
            return pos;
        }


    }
}